/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package oneStopShop.Util;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import oneStopShop.Beans.Customer;

/**
 *
 * @author Administrator
 */
public class CustomerTableModel extends AbstractTableModel {

    private int colnum = 5;
    private String[] colNames = {"ID", "Name", "Address", "Contact No", "Customre type"};
    private ArrayList<String[]> ResultSets;

public static String getStringCustomerType(int i){
     if (i==1) {
            return "Retail Normal";
        }
        if (i==2) {
            return "Retail VIP";
        }
        if (i==3) {
            return "Large Order";
        }
        if (i==4) {
            return "Mail Order";
        }

        return null;

}
    public CustomerTableModel(List<Customer> customerList) {

        ResultSets = new ArrayList<String[]>();


        for (Customer cus : customerList) {

            String[] row = {Integer.toString(cus.getCustomerNumber()), cus.getName(), cus.getAddress(), Integer.toString(cus.getContactNumber()), CustomerTableModel.getStringCustomerType(cus.getCustomerType())};

            ResultSets.add(row);

        }


    }

    public Object getValueAt(int rowindex, int columnindex) {

        String[] row = ResultSets.get(rowindex);
        return row[columnindex];

    }

    public int getRowCount() {
        return ResultSets.size();
    }

    public int getColumnCount() {
        return colnum;
    }

    public String getColumnName(int param) {

        return colNames[param];
    }
}
